﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace Xcj.Mes.WholeLine.ZH.HG.Shell.Converter
{
    public class InFeedResultConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (((values?.Length ?? 0) < 2) || (values[0] == null) || (values[1] == null))
                return string.Empty;

            try
            {
                int openShortCircuitResult = int.Parse(values[0]?.ToString()?.Trim() ?? "0");
                int labelResult = int.Parse(values[1]?.ToString()?.Trim() ?? "0");

                /*
                 * 开短路状态数据 00 无料 20 良品 11 开短路不良 12 重测 13 超上限(短路) 14 超下限(开路) 15 未触发或过流
                 */

                if ((openShortCircuitResult == 20) && ((labelResult == 20) || (labelResult == 0)))
                    return "良品";
                else
                {
                    if (openShortCircuitResult == 11)
                        return "开短路不良";
                    else if (openShortCircuitResult == 12)
                        return "开短路重测";
                    else if (openShortCircuitResult == 13)
                        return "短路不良";
                    else if (openShortCircuitResult == 14)
                        return "开路不良";
                    else if ((labelResult != 20) && (labelResult != 0))
                        return "标识不良";
                    else
                        return "重测";
                }
            }
            catch { }

            return "重测";
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}